<?php

class MockIOC {

  function get($name) {
    switch ($name) {
      case 'foo-ref': return 'fooObj';
      case 'bar-ref': return 'barObj';
      default: return null;
    }
  }
  
}

class FactoryTest extends UnitTestCase {

  var $m_mockIOC;
  var $m_factory;
  var $m_dataPath;

  function setUp() {
    parent::setUp();
    $this->m_mockIOC =& new MockIOC();
    $this->m_dataPath = TEST_DATA.'factory/';
    $this->m_factory =& new PicoIOCFactory($this->m_mockIOC);
  }

  function tearDown() {
    $this->m_factory = null;
    $this->m_mockIOC = null;
    $this->m_dataPath = null;
    parent::tearDown();
  }

  function testBindConst() {
    $obj =& new MockObject();
    $this->m_factory->bind_const($obj, array('foo' => 'fooConst', 'bar' => 'barConst'));
    $this->assertIdentical($obj->get_foo(), 'fooConst');
    $this->assertIdentical($obj->get_bar(), 'barConst');
  }
  
  function testBindObj() {
    $obj =& new MockObject();
    $this->m_factory->bind_obj($obj, array('foo' => 'foo-ref', 'bar' => 'bar-ref'));
    $this->assertIdentical($obj->get_foo(), 'fooObj');
    $this->assertIdentical($obj->get_bar(), 'barObj');
  }

  function testSingleton() {
    $instance =& $this->m_factory->instantiate($this->m_dataPath.'singleton.inc.php');
    $this->assertTrue($this->m_factory->is_singleton());
  }
  
  function testNonSingleton() {
    $instance =& $this->m_factory->instantiate($this->m_dataPath.'non-singleton.inc.php');
    $this->assertFalse($this->m_factory->is_singleton());
  }

  function testPostConfigure() {
    $instance =& $this->m_factory->instantiate($this->m_dataPath.'configured.inc.php');
    $this->assertIdentical($instance->get_config_count(), 1);
  }
  
  function testNoPostConfigure() {
    $instance =& $this->m_factory->instantiate($this->m_dataPath.'non-configured.inc.php');
    $this->assertIdentical($instance->get_config_count(), 0);
  }
  
}
  

?>
